class Solution {
    /**
        动态规划：
    */
    public int minPathSum(int[][] grid) {
        int n = grid.length, m = grid[0].length;
        int[][] d = new int[n+1][m+1];
        for(int i=2; i<=n; i++) d[i][0] = Integer.MAX_VALUE;
        for(int j=2; j<=m; j++) d[0][j] = Integer.MAX_VALUE;
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++)
                d[i+1][j+1] = Math.min(d[i+1][j],d[i][j+1]) + grid[i][j];
        }
        return d[n][m];
    }
}